package com.swanclouds.redfish.shared;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.swanclouds.model.shared.RootResource;
import com.swanclouds.redfish.common.redfish.MemberModel;
import com.swanclouds.redfish.common.utils.StringHepler;

import java.util.Map;

/**
 * 跟资源实体类
 *
 * @author 张立强
 */
public class RootResourceConcrete implements RootResource {

    @JsonProperty("UUID")
    private String uUID;

    @JsonProperty("RedfishVersion")
    private String redfishVersion;
    /**
     * 设备的全局唯一标识符
     *
     * @return UUID
     */
    @Override
    public String getUUID() {
        return this.uUID;
    }

    /**
     * Redfish 详细版本信息
     *
     * @return redfishVersion
     */
    @Override
    public String getRedfishVersion() {
        return this.redfishVersion;
    }

    @JsonProperty("Systems")
    private MemberModel systems;

    @JsonProperty("Chassis")
    private MemberModel chassis;

    @JsonProperty("Managers")
    private MemberModel managers;

    @JsonProperty("Tasks")
    private MemberModel tasks;

    @JsonProperty("SessionService")
    private MemberModel sessions;

    @JsonProperty("AccountService")
    private MemberModel accounts;

    @JsonProperty("EventService")
    private MemberModel events;

    @JsonProperty("UpdateService")
    private MemberModel updates;

    @JsonProperty("Registries")
    private MemberModel registries;

    @Override
    public Boolean suportSystems() {
        return systems != null && StringHepler.isNotBlank(systems.getDataId());
    }

    @Override
    public Boolean suportChassis() {
        return chassis != null && StringHepler.isNotBlank(chassis.getDataId());
    }

    @Override
    public Boolean suportManagers() {
        return managers != null && StringHepler.isNotBlank(managers.getDataId());
    }

    @Override
    public Boolean suportTasks() {
        return tasks != null && StringHepler.isNotBlank(tasks.getDataId());
    }

    @Override
    public Boolean suportSessionService() {
        return sessions != null && StringHepler.isNotBlank(sessions.getDataId());
    }

    @Override
    public Boolean suportAccountService() {
        return accounts != null && StringHepler.isNotBlank(accounts.getDataId());
    }

    @Override
    public Boolean suportEventService() {
        return events != null && StringHepler.isNotBlank(events.getDataId());
    }

    @Override
    public Boolean suportUpdateService() {
        return updates != null && StringHepler.isNotBlank(updates.getDataId());
    }

    @Override
    public Boolean suportRegistries() {
        return registries != null && StringHepler.isNotBlank(registries.getDataId());
    }

    @JsonProperty("@odata.id")
    private String dataId;
    @JsonProperty("@odata.context")
    private String context;
    @JsonProperty("@odata.type")
    private String type;
    @JsonProperty("Name")
    private String name;
    /**
     * 集合资源的访问路径 @odata.id
     * @return dataId
     */
    @Override
    public String getDataId() {
        return this.dataId;
    }

    /**
     * 资源名称 Name
     * @return name
     */
    @Override
    public String getName() {
        return this.name;
    }

    /**
     * 集合资源模型的描述信息 @odata.context
     * @return context
     */
    @Override
    public String getContext() {
        return this.context;
    }

    /**
     * 集合资源的类型 @odata.type
     * @return type
     */
    @Override
    public String getType() {
        return type;
    }

    @JsonProperty("Id")
    private String id;
    @JsonProperty("Vendor")
    private String vendor;
    @JsonProperty("Product")
    private String product;
    @JsonProperty("Oem")
    private Map<String,Object> oem;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getVendor() {
        return vendor;
    }

    public void setVendor(String vendor) {
        this.vendor = vendor;
    }

    public String getProduct() {
        return product;
    }

    public void setProduct(String product) {
        this.product = product;
    }

    public Map<String, Object> getOem() {
        return oem;
    }

    public void setOem(Map<String, Object> oem) {
        this.oem = oem;
    }

    @Override
    public String toString() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
        }
        return "RootResourceConcrete {" +
                "dataId='" + dataId + '\'' +
                ", context='" + context + '\'' +
                ", id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", type='" + type + '\'' +
                ", uUID='" + uUID + '\'' +
                ", redfishVersion='" + redfishVersion + '\'' +
                (vendor != null ? ", vendor='" + vendor + '\'' : "") +
                ", product='" + product + '\'' +
                (oem != null ? ", oem=" + oem : "") +
                '}';
    }
}
